<template>
  <view>
    
  </view>
</template>

<script>
  export default {
    name: "form-page",
    props: {
      v2Data: {
        type: Object
      },
    },
    computed: {
      tabsChild() {
        return this.v2Data.child_service.filter(item => item?.foreign_key?.show_ui_model === 'tabs')
      },
      collapseChild() {
        if (Array.isArray(this.v2Data?.child_service)) {
          return this.v2Data.child_service.filter(item => item?.foreign_key?.show_ui_model === 'collapse')
        }
      }
    },
    data() {
      return {
        childV2List: []
      };
    },
    methods: {
      async getChildV2(e) {
        console.log(e)
        let app = uni.getStorageSync('activeApp');
        let colVs = await this.getServiceV2(e.service_name, 'detail', 'detail', e.srv_app);
        if (colVs.more_config && typeof colVs.more_config === 'string') {
          try {
            colVs.moreConfig = JSON.parse(colVs.more_config)
          } catch (e) {
            console.log(e)
            debugger
            //TODO handle the exception
          }
        }
        let foreign_key = e.foreign_key;

        let condition = [{
          colName: "project_number",
          ruleType: "eq",
          value: "CRFG2021-YB-066"
        }]
        let mainData = this.$refs.bxForm.getFieldModel();
        if (foreign_key?.relation_type === '服务') {
          if (foreign_key?.view_model === 'detail' && colVs?._fieldInfo) {
            if (foreign_key?.ref_app && foreign_key?.ref_service && foreign_key?.ref_service_column && mainData &&
              mainData[foreign_key.refed_service_column]) {

            }
            let defaultVal = await this.getDefaultVal(e.service_name, e.srv_app, condition);
            colVs.fields = this.setFieldsDefaultVal(colVs._fieldInfo, defaultVal || {});
            colVs.view_model = 'detail'
          }
        }
        return colVs
      },
      changeTab(index) {
        this.curTab = index
        if (index > 0) {
          if (this.childV2List.length === 0 && Array.isArray(this.childService) && this.childService.length > 0) {
            this.childV2List = new Array(this.childService.length)
          }
          this.getChildV2(this.childService[index - 1]).then(res => {
            this.$set(this.childV2List, index - 1, res)
          })
        }
      },
    },
  }
</script>

<style>

</style>
